#pragma once
#include "Algorithm.h"
#include "SystemView.h"
#include "GradientDescent.h"
#include <list>
#include <map>
#include <string>

using namespace std;

class CostAlgo : public Algorithm
{
private:

	double G;	// geometric factor
	int L;		// horizon - current inifine
	GradientDescent* GD;	// the priority changing algorithm
	int numOfExchanges;
	int exchangeLimit;
	int oldSsd, oldFc;	// number of extents previously in the ssd/fc
	int fcNum, ssdNum, sortedNum;	// where are we in searching for someone to remove from the relevent device
	vector<ExtentStatsAlgo*>::iterator sortIt;
	vector<ExtentStatsAlgo*>::iterator ssdIter, fcIter;		// where to insert the extent in the ssd vector and in the fc vector

	int findOldPlace(ExtentStatsAlgo*);
	void createSortedExtents(vector<ExtentEntry*>* extents, int timeToDelete, int currentTime);
	void addToSorted(vector<ExtentEntry*>::iterator itList);
	bool alreadyExistsInSortedExtents(ExtentEntry* ex);
	void noMoreExchanges();
	bool removeFromSsd(int fcSpace);
	bool removeFromFc();
	void decreaseOld(int place);
	double divisionOfPriorityGroup(vector<ExtentStatsAlgo*>* l, int groupNo, int time);
	
public:
	
	CostAlgo(SystemView* sys, int sortType, Writer* w, Parser* prs, double constantG, int noTimeSlices, int limit);
	virtual ~CostAlgo(void);
	void runAlgo(int iteration);

};
